package ACWing.Dynamicprogramming;
//55. 连续子数组的最大和

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/11/22 23:05
 */
public class TheLargestSumOfConsecutiveSubarrays {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[]nums=new int[n+1];
        for (int i = 1; i <= n; i++) {
            nums[i]=sc.nextInt();
        }
        System.out.println(maxSubArray(nums));

    }
    public static int maxSubArray(int[] nums) {
        int len=nums.length;
        int max=(int)-1.0E6;
        int sum=0;
        for (int i = 1; i < len; i++) {
            sum=sum+nums[i];
            max=Math.max(sum,max);
            if(sum<=0){
                sum=0;
            }
        }
        return max;
    }

}
